package client.comm.baoding.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import client.comm.commlib.base.BindingViewHoder
import client.comm.baoding.R
import client.comm.baoding.api.bean.TxJl
import client.comm.baoding.api.bean.Zcjl
import client.comm.baoding.databinding.LayoutMxjlitemBinding
import client.comm.commlib.base.BasePagingAdapter
import client.comm.commlib.base.PagingViewHoder
import com.bumptech.glide.RequestManager
import com.google.gson.Gson

class ZcjlAdapter(val context: Context, val manager: RequestManager) : BasePagingAdapter<Zcjl.Record>(object : DiffUtil.ItemCallback<Zcjl.Record>() {
    val g = Gson()

    override fun areItemsTheSame(
        oldItem: Zcjl.Record,
        newItem: Zcjl.Record
    ): Boolean {
        return true
    }

    override fun areContentsTheSame(
        oldItem: Zcjl.Record,
        newItem: Zcjl.Record
    ): Boolean {
        return g.toJson(oldItem).equals(g.toJson(newItem))
    }
}){

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutMxjlitemBinding
        val bean = t as Zcjl.Record

        when (bean.r_state) {
            1 -> {
                binding.num = "+${bean.num}"
            }
            2 -> {
                binding.num = "-${bean.num}"
            }
        }
        binding.bean = bean
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_mxjlitem
    }
}